import 'package:eh_mobile/common/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import '../controller.dart';

class HomeShortCutView extends StatefulWidget {
  HomepageController controller;
   HomeShortCutView({ required this.controller,  super.key});

  @override
  State<HomeShortCutView> createState() => _HomeShortCutViewState();
}

class _HomeShortCutViewState extends State<HomeShortCutView> {


  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: buildShortcutItems(),
    );
  }

  // 创建快捷面板子视图
  List<Widget> buildShortcutItems() {
    double itemWidth = (1.sw - 48.w) / 3.0;
    final items = <Widget>[];
    for (var i = 0; i <widget.controller.shortcutList.length; i++) {
      Map shortcutMap = widget.controller.shortcutList[i];
      Widget container = Container(
        height: 42.h,
        width: itemWidth,
        padding: const EdgeInsets.only(left: 17, right: 17).r,
        decoration: BoxDecoration(
            color: const Color.fromRGBO(0, 150, 208, 0.15),
            borderRadius: BorderRadius.circular(13.r),
            border: Border.all(
              width: 2,
              color: const Color.fromRGBO(0, 150, 208, 1),
            )),
        child: Row(
          children: [
            SvgPicture.asset(
              shortcutMap['icon'],
              colorFilter:
                  const ColorFilter.mode(Colors.white, BlendMode.srcIn),
            ),
            12.sizedBoxWidth,
            Text(shortcutMap['title'], style: 16.ts)
          ],
        ),
      );

      items.add(container);

      if (i < widget.controller.shortcutList.length - 1) {
        items.add(12.sizedBoxWidth);
      }
    }
    return items;
  }
}
